package com.app.GoCuro;

import java.util.ArrayList;

import com.app.GoCuro.util.CustomHttpClient;
import com.app.GoCuro.util.DatabaseInformation;
import com.app.GoCuro.util.DatabaseItem;
import com.app.GoCuro.util.LoginResponse;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class ViewItemsActivity extends Activity {

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.view_items);

		final ListView itemList = (ListView) findViewById(R.id.database_items);

		LoginResponse loginResponse = (LoginResponse) getIntent()
				.getSerializableExtra("curr_user");
		DatabaseInformation databaseInfo = (DatabaseInformation) getIntent()
				.getSerializableExtra("selected_database");
		CustomHttpClient client = new CustomHttpClient(this);

		ArrayList<DatabaseItem> databaseItems = client.getDatabaseItems(
				loginResponse.getUserName(), loginResponse.getPwd(),
				databaseInfo.getId());

		// do not setup the items if the databases are null
		if (databaseItems == null)
			return;

		// copy the strings over to an array for passage into an array adapter
		// convert the names of the databases into ArrayList<String> for passing
		// to the ArrayAdapter
		ArrayList<String> barcodes = new ArrayList<String>();
		for (int i = 0; i < databaseItems.size(); i++) {
			barcodes.add(databaseItems.get(i).getBarcode());
		}

		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, barcodes);
		itemList.setAdapter(adapter);

		// TODO Auto-generated method stub
	}

}
